﻿@{
    
    // Connecting to webservices
    RemoteService.WebRemoteServiceClient _remoteService = new RemoteService.WebRemoteServiceClient();
    
    // Get specific movie from id
    RemoteService.Movie m = _remoteService.GetMovie(Convert.ToInt32(Request.Params["id"]));
    
    // Get Cinemas
    List<RemoteService.Cinema> _cinemas = _remoteService.GetCinemas();

    IEnumerable<RemoteService.ScreenCast> screenCasts = new List<RemoteService.ScreenCast>();
    
    if (Request.Cookies["bioId"] != null && Request.Cookies["bioName"] != null)
    {   
        RemoteService.Cinema cinema = _cinemas.Where(c => c.Id == Convert.ToInt32(Request.Cookies["bioId"].Value)).Single();

        // Get screencasts for movie (Should take bio id as parameter too)
        _remoteService.GetScreenCasts(m, cinema);
        screenCasts = _remoteService.GetScreenCasts(m, cinema);

        // Order screen casts by date
        screenCasts = screenCasts.OrderBy(sc => sc.Airdate);
        
    }

    // Used to control print of new dates in airtime list
    DateTime lastDateTime = new DateTime();

    // Save Movieid in cookie
    if (Request.QueryString["id"] != null && Request.QueryString["id"].Count() > 0)
    {
        Response.Cookies["bioMovie"].Value = Request.QueryString["id"];
        Response.Cookies["bioMovie"].Expires = DateTime.Now.AddDays(1);
    }       
    
    Page.Title = "Select movie";
    Layout = "~/_SiteLayout.cshtml";
}


@section featured {
<section class="featured">
    <div class="content-wrapper">
        <hgroup class="title">
            <p>Below you can find information about @m.Title and order tickets.</p>
            <span class="bookingButton">Book tickets</span>
        </hgroup>
    </div>
</section>
}

<script type="text/javascript">
    $(document).ready(function () {
        $(document).on('click', '.bookingButton', function (e) {
            $(".outer").fadeIn();
            $(".modal2").fadeIn();
            $(".modalboxOverlay").fadeIn();

            // Building screencast menu using jQuery and C#
            $(".modal2").html("@foreach(RemoteService.ScreenCast sc in screenCasts) 
                               {
                                   if (sc.Airdate.Date == DateTime.Today && sc.Airdate.Date != lastDateTime.Date)
                                   { lastDateTime = sc.Airdate; <h1>Today (<i>@sc.Airdate.Date.ToString("MMMM dd, yyyy")</i>)</h1> } else if (sc.Airdate.Date == DateTime.Today.AddDays(1) && sc.Airdate.Date != lastDateTime.Date) { lastDateTime = sc.Airdate; <h1>Tomorrow (<i>@sc.Airdate.Date.ToString("MMMM dd, yyyy")</i>)</h1> } else if (sc.Airdate.Date != lastDateTime.Date) { lastDateTime = sc.Airdate; <h1>@sc.Airdate.Date.ToString("MMMM dd, yyyy")</h1> }
                                   <div class='listBlocks 1'><a href='~/Booking?screencastId=@sc.Id'>@sc.Airdate.TimeOfDay - HALL @_remoteService.GetMovieHallUsingScreenCast(sc).Number</a></div>}");
                               
        });
    });

</script>

<div class="movieBlock">
    <!-- Adding movie information -->
    <h2>@m.Title</h2><br/>
        @{
            if (m.ImgUrl != "") 
            {
                <img class="poster" src="@m.ImgUrl" />
            } else 
            {
               <img class="poster" src="images/question%20mark.jpg" />
            }
        }
    <div class="discription">
        <h3>Description</h3>
        <p>@m.Description</p><br />
        <span style="display: block;"><b>Genre:</b> @m.Genre</span>
        <span style="display: block; margin-top: 10px;"><b>Duration:</b> @m.Length min</span>
    </div>
    <div class="actors">
        <h3>Actors</h3>
        <!-- Adding actors to window -->
        <ul>
            @{
                foreach (RemoteService.Actor a in m.Actors)
                {
                    <li>@a.Name</li>
                }  
            }
        </ul>
    </div>
</div>